package com.yuyou.fn.timer.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import com.yuyou.fn.tradingservice.entity.LeaseMessage;
import com.yuyou.fn.tradingservice.entity.ServiceProduct;
import com.yuyou.fn.tradingservice.service.ILeaseMessageService;
import com.yuyou.fn.tradingservice.service.IServiceProductService;
import com.yuyou.fn.tradingservice.vo.LeaseMessageQueryVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by lzh on 2017/08/14.
 */
@JobHander(value="OffServiceProductTask")
@Component
public class OffServiceProductTask extends IJobHandler {

    @Resource
    private IServiceProductService serviceProductService;

    @Resource
    private ILeaseMessageService leaseMessageService;

    @Override
    public ReturnT<String> execute(String... strings) throws Exception {
        Calendar cal = Calendar. getInstance ();
        cal.add(Calendar.DATE,1);
        Date date=cal.getTime();
        LeaseMessageQueryVo leaseMessageQueryVo = new LeaseMessageQueryVo();
        leaseMessageQueryVo.setLessEndTime(date);
        leaseMessageQueryVo.setStatus(1);
        List<LeaseMessage> leaseMessageList = leaseMessageService.findLeaseMessage(leaseMessageQueryVo);
        for (LeaseMessage leaseMessage:leaseMessageList){
            leaseMessageService.offLease(leaseMessage.getLeaseId(),0,leaseMessage.getProductId());
        }
        List<ServiceProduct> serviceProductList=serviceProductService.findByInventoryAndStatusAndType(0,0,1);
        for (ServiceProduct serviceProduct:serviceProductList){
            serviceProductService.onOrOff(null,serviceProduct.getProductId(),0,2);
        }

        return ReturnT.SUCCESS;
    }


}
